//
//  TurnOverBoxCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/7/28.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "TurnOverBoxCell.h"

@interface TurnOverBoxCell ()

@property (nonatomic, strong) UITextField *textField;

@end

@implementation TurnOverBoxCell

+ (instancetype)TurnOverBoxCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"TurnOverBoxCell";
    TurnOverBoxCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[TurnOverBoxCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.textField = [[UITextField alloc] initWithFrame:CGRectMake(15, 10, ScreenW - 30, 60)];
        self.textField.placeholder = @"输入/扫一扫";
        self.textField.textColor = HexColor(0x333333);
        self.textField.font = [UIFont systemFontOfSize:16];
        self.textField.backgroundColor = HexColor(0xffffff);
        self.textField.layer.masksToBounds = YES;
        self.textField.layer.cornerRadius = 6;
        [self.contentView addSubview:self.textField];
        
        UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 61, 60)];
        leftView.backgroundColor = [UIColor clearColor];
        UIButton *scanBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 12, 36, 36)];
        scanBtn.backgroundColor = HexColorA(0x3D68EB, 0.1);
        scanBtn.layer.masksToBounds = YES;
        scanBtn.layer.cornerRadius = 6;
        [scanBtn setImage:[UIImage imageNamed:@"icon_qr_2"] forState:0];
        [scanBtn addTarget:self action:@selector(scanClick) forControlEvents:UIControlEventTouchUpInside];
        [leftView addSubview:scanBtn];
        self.textField.leftView = leftView;
        self.textField.leftViewMode = UITextFieldViewModeAlways;
        
        UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 42, 60)];
        rightView.backgroundColor = [UIColor clearColor];
        UIButton *deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(10, 19, 22, 22)];
        [deleteBtn setImage:[UIImage imageNamed:@"icon_scan_install_delete"] forState:0];
        [deleteBtn addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
        [rightView addSubview:deleteBtn];
        self.textField.rightView = rightView;
        self.textField.rightViewMode = UITextFieldViewModeAlways;
        
        self.height = self.textField.nim_bottom;
    }
    return self;
}

- (void)scanClick {
    if (self.scanBlock) {
        self.scanBlock();
    }
}

- (void)deleteClick {
    if (self.deleteBlock) {
        self.deleteBlock();
    }
}

-(void)setModel:(TurnOverBoxModel *)model {
    _model = model;
    if (model.boxNO.length) {
        self.textField.text = model.boxNO;
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
